package P819;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

/**
 * Problema da disciplina de Estrutura de Dados e Complexidade de Algoritmos da
 * Pos Graduacao do Periodo 2011.1
 *
 * @see http://br.spoj.pl/problems/PEDAGIO/
 * @author Elenilson Vieira - 111100371 - elenilson[at]elenilsonvieira.com
 * @since 8 de junho de 2011
 */
public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        String line = null;
        int testNumber = 1;
        StringBuilder result = new StringBuilder();

        while (!(line = reader.readLine().trim()).equals("0 0 0 0")) {
            String data[] = line.split(" ");
            int citiesAmount = Integer.parseInt(data[0]);
            int roadsAmount = Integer.parseInt(data[1]);
            int jucaCity = Integer.parseInt(data[2]);
            int maxToll = Integer.parseInt(data[3]);
            StringBuilder cities = new StringBuilder();
            boolean citiesToVisit[] = new boolean[citiesAmount];
            boolean graph[][] = new boolean[citiesAmount][citiesAmount];

            for (int i= 0; i < roadsAmount; i++) {
                line = reader.readLine();
                data = line.split(" ");
                int x = Integer.parseInt(data[0]);
                int y = Integer.parseInt(data[1]);

                graph[x - 1][y - 1] = true;
                graph[y - 1][x - 1] = true;
            }

            Set<Integer> levelCities = new HashSet<Integer>();
            levelCities.add(jucaCity - 1);

            for (int i= 0; i < maxToll; i++) {
                Set<Integer> nextLevelCities = new HashSet<Integer>();

                for (int levelCitie : levelCities) {
                    for (int j= 0; j < citiesAmount; j++) {
                        if(graph[levelCitie][j] && j + 1 != jucaCity){
                            citiesToVisit[j] = true;
                            nextLevelCities.add(j);
                        }
                    }
                }

                levelCities = nextLevelCities;
            }

            for (int i= 0; i < citiesToVisit.length; i++) {
                if(citiesToVisit[i]){
                    cities.append(i + 1).append(" ");
                }
            }

            result.append(String.format("Teste %d\n%s\n\n", testNumber++, cities.toString().trim()));
        }

        System.out.print(result.toString());
    }
}
